home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 24 / Mac Magazin and MacEasy Magazine CD - Issue 24.iso / Wissenschaft & Technik / ProgressCDEF ƒ / ProgressCDEF Demo ƒ / ProgressCDEF Demo.c < prev    next >
C/C++ Source or Header  |  1996-06-22  |  7KB  |  308 lines

  1. #include "ProgressCDEF Demo.h"
  2.  
  3.  
  4. /*******************************************************************************
  5.  
  6.     •••    main •••
  7.  
  8. *******************************************************************************/
  9. main()
  10. {
  11.     InitToolbox();
  12.     InitScoreCard();
  13.     MainEventLoop();
  14.     DoQuit();
  15. }
  16.  
  17.  
  18. /*******************************************************************************
  19.  
  20.     •••    InitToolbox    •••
  21.  
  22. *******************************************************************************/
  23. void InitToolbox()
  24. {
  25.     Handle            menuBar;
  26.     EventRecord     event;
  27.  
  28.  
  29.     gInBackground = false;
  30.     gQuit = false;
  31.  
  32.     InitGraf( (Ptr) &qd.thePort);
  33.     InitFonts();
  34.     FlushEvents( everyEvent, 0);
  35.     InitWindows();
  36.     InitMenus();
  37.     TEInit();
  38.     InitDialogs(NIL);
  39.     InitResources();
  40.     MaxApplZone();
  41.  
  42.  
  43.     for ( count = 1; count <= 3; ++count)        EventAvail(everyEvent, &event);
  44.     SysEnvirons( curSysEnvVers, &gMac);
  45.         if ( gMac.systemVersion < 0x0700)        BadAlert(errWimpySystem);
  46.  
  47.     menuBar = GetNewMBar( 128);
  48.     if (!menuBar)                        BadAlert(errCorrupt);
  49.     SetMenuBar(menuBar);        
  50.     DisposHandle(menuBar);
  51.     AddResMenu( GetMHandle(mApple), 'DRVR');
  52.     DrawMenuBar();
  53.  
  54.     InitCursor();
  55. }
  56.  
  57.  
  58. /*******************************************************************************
  59.  
  60.     •••    MainEventLoop    •••
  61.  
  62. *******************************************************************************/
  63. void MainEventLoop( void )
  64. {
  65.     Boolean            gotEvent;
  66.     EventRecord        event;
  67.  
  68.     while (!gQuit)
  69.     {
  70.         gotEvent = WaitNextEvent( everyEvent, &event, 15, NIL);
  71.         if (gotEvent)        HandleEvent(&event);
  72.         else                DoIdle(&event);
  73.     }
  74. }
  75.  
  76.  
  77. /*******************************************************************************
  78.  
  79.     •••    HandleEvent    •••
  80.  
  81. *******************************************************************************/
  82. void HandleEvent( EventRecord *event)
  83. {
  84.     WindowPtr        theWindow;
  85.     short            part = FindWindow( event->where, &theWindow);
  86.     
  87.     switch (event->what)
  88.     {        
  89.         case mouseDown:            HandleMouseDown(event);                break;
  90.         case keyDown:
  91.         case autoKey:            HandleKeyPress(event);                break;
  92.         case activateEvt:        PrepareActivateEvent(event);        break;
  93.         case updateEvt:            HandleUpdateEvent(event);            break;
  94.         case diskEvt:            HandleDiskInsert(event);            break;
  95.         case osEvt:
  96.             switch (( event->message >> 24) & 0x00FF)
  97.             {
  98.                 case suspendResumeMessage:
  99.                     gInBackground = HandleOSEvent(event);
  100.                     break;
  101.             }
  102.             break;
  103.     }
  104. }
  105.  
  106.  
  107. /*******************************************************************************
  108.  
  109.     •••    HandleDiskInsert    •••
  110.  
  111. *******************************************************************************/
  112. void HandleDiskInsert( EventRecord *event)
  113. {
  114.     Point    aPoint = { 100, 104};
  115.  
  116.     if ( HiWord( event->message) != noErr )
  117.     {
  118.         (void) DIBadMount( aPoint, event->message);
  119.     }
  120. }
  121.  
  122.  
  123. /*******************************************************************************
  124.  
  125.     •••    HandleKeyPress    •••
  126.  
  127. *******************************************************************************/
  128. void HandleKeyPress( EventRecord *event)
  129. {
  130.     char    key = event->message & charCodeMask;
  131.     if ( event->modifiers & cmdKey)            HandleMenuCommand( MenuKey(key));
  132. }
  133.  
  134.  
  135. /*******************************************************************************
  136.  
  137.     •••    HandleMouseDown    •••
  138.  
  139. *******************************************************************************/
  140. void HandleMouseDown( EventRecord *event)
  141. {
  142.     DialogPtr    d;
  143.     short        i, part = FindWindow( event->where, &theWindow);
  144.     Boolean        dlgEvent;
  145.  
  146.  
  147.     switch (part)
  148.     {
  149.         case inMenuBar:        HandleMenuCommand( MenuSelect(event->where));        break;
  150.         case inSysWindow:
  151.             SystemClick( event, theWindow);
  152.             break;
  153.         case inDrag:
  154.             if ( theWindow == FrontWindow())
  155.             {
  156.                 DragWindow( theWindow, event->where, &qd.screenBits.bounds);
  157.             }
  158.             break;
  159.         case inGoAway:
  160.             if (TrackBox( theWindow, event->where, part))            DoQuit();
  161.             break;
  162.         case inContent:
  163.             d = FrontWindow();
  164.             dlgEvent = DialogSelect( event, &d, &i);
  165.             if (dlgEvent)        HandleDialogClick( d, i);
  166.             break;
  167.     }
  168. }
  169.  
  170.  
  171. /*******************************************************************************
  172.  
  173.     •••    HandleMenuCommand    •••
  174.  
  175. *******************************************************************************/
  176. void HandleMenuCommand( long menuResult)
  177. {
  178.     Str255        daName;
  179.     short        menuID, menuItem;
  180.  
  181.  
  182.     menuID = HiWord(menuResult);
  183.     menuItem = LoWord(menuResult);
  184.  
  185.     switch (menuID)
  186.     {
  187.         case mApple:
  188.             switch (menuItem)
  189.             {
  190.                 case iAbout:            break;
  191.                 default:
  192.                     GetItem( GetMHandle(mApple), menuItem, daName);
  193.                     (void) OpenDeskAcc(daName);
  194.                     break;
  195.             }
  196.             break;
  197.  
  198.         case mFile:
  199.             gQuit = true;
  200.             break;
  201.     }
  202.     HiliteMenu(0);
  203. }
  204.  
  205.  
  206. /*******************************************************************************
  207.  
  208.     ••• HandleDialogClick()         23/1/1994 at 16:30 •••
  209.     
  210. *******************************************************************************/
  211. void HandleDialogClick( DialogPtr d, short i)
  212. {
  213.     ControlRef        pBar, button;
  214.     Handle            ih;
  215.     Rect            ir;
  216.     long            dl;
  217.     short            j, it, ctlItem, oldValue;
  218.  
  219.  
  220.     if ( i > 2)        return;
  221.  
  222.     GetDialogItem( d, i, &it, &ih, &ir);        button = (ControlRef) ih;
  223.     GetDialogItem( d, i + 2, &it, &ih, &ir);    pBar = (ControlRef) ih;
  224.     HiliteControl( button, 255);
  225.     oldValue = GetDValue( d, i + 2);
  226.  
  227.     for ( j = 1; j <= 96; ++j)        SetControlValue( pBar, oldValue + j);
  228.  
  229.     SetControlValue( pBar, oldValue);
  230.     GetDialogItem( d, i, &it, &ih, &ir);
  231.     HiliteControl( button, 0);
  232. }
  233.  
  234.  
  235. /*******************************************************************************
  236.  
  237.     ••• HandleUpdateEvent()         24/1/1994 at 18:26 •••
  238.     
  239. *******************************************************************************/
  240. void HandleUpdateEvent( EventRecord *e)
  241. {
  242.     DialogPtr    d = (DialogPtr) e->message;
  243.     short        x;
  244.  
  245.     BeginUpdate(d);
  246.         UpdateDialog( d, d->visRgn);
  247.     EndUpdate(d);
  248. }
  249.  
  250.  
  251. /*******************************************************************************
  252.  
  253.     ••• DoQuit        26/1/1994 at 20:12 •••
  254.  
  255. *******************************************************************************/
  256. void DoQuit()
  257. {
  258.     DialogPtr    d = FrontWindow();
  259.  
  260.     if (d)        DisposeDialog(d);
  261.     gQuit = true;
  262. }
  263.  
  264.  
  265. /*******************************************************************************
  266.  
  267.     •••    DoIdle            18/9/1995 at 18:56 •••
  268.  
  269. *******************************************************************************/
  270. void DoIdle( EventRecord *event)
  271. {
  272.     DialogPtr        fd = FrontWindow();
  273.     short            i;
  274.     Boolean            result;
  275.  
  276.     if (fd)            result = DialogSelect( event, &fd, &i);
  277. }
  278.  
  279.  
  280. /*******************************************************************************
  281.  
  282.     •••    PrepareActivateEvent            20/9/1995 at 17:32 •••
  283.  
  284. *******************************************************************************/
  285. void PrepareActivateEvent( EventRecord *event)
  286. {
  287.     WindowPtr    w;
  288.     Boolean        activate;
  289.  
  290.     activate = ( event->modifiers & activeFlag) != 0;
  291.     w = (WindowPtr) event->message;
  292.     if (w)        HandleActivateEvent( w, activate, event);
  293. }
  294.  
  295.  
  296. /*******************************************************************************
  297.  
  298.     •••    HandleActivateEvent            20/9/1995 at 12:48 •••
  299.  
  300. *******************************************************************************/
  301. void HandleActivateEvent( WindowPtr w, Boolean activate, EventRecord *event)
  302. {
  303.     short        i;
  304.     Boolean        handled;
  305.  
  306.     SetPort(w);
  307.     handled = DialogSelect( event, &w, &i);
  308. }